package czh.aqxn.readdata;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import czh.aqxn.readdata.bean.IndicatorBean;
import czh.util.DateUtil;

import java.util.Date;

public class ReadExcelData {
    static int i =6949;


    public static void main(String[] args) {
        // 读取文件的路径
        final String excelFilePath = "D:\\work\\安全小脑\\第四波处理后\\凯美特.xls";

        // 读取excel
        EasyExcel.read(excelFilePath, IndicatorBean.class, new AnalysisEventListener<IndicatorBean>() {
            // 每读取一行数据, 该方法会被调用一次
            @Override
            public void invoke(IndicatorBean testExcel, AnalysisContext analysisContext) {
                i++;
                //System.out.println("读取了一行");
                //System.out.println("testExcel " + testExcel);
                System.out.println("INSERT INTO `dyw_tsingyun_alarm`.`alarm_indicator_draft`(`id`, `name`, `num`, `sys_num`, `org_code`, `poi_id`, `poi_type`, `indicator_type`, `indicator_factor`, `indicator_unit`, `status`, `report_status`, `running_status`, `range_top`, `range_bottom`, `norms`, `collect_rate`, `collector_id`, `normal_threshold_top`, `normal_threshold_bottom`, `manufacturer`, `cuser_id`, `ctime`, `uuser_id`, `utime`, `delete_status`, `sort_id`, `relate_alarm`, `disabled`, `target_code`, `gateway_code`, `tenant_id`) VALUES ( "+i+",'"+testExcel.getName()+"', '"+testExcel.getNum()+"', '"+testExcel.getNum()+"', '419345796366860288', '-1', '13', '', NULL, '', 0, 1, 1, 0.00, 0.00, '', NULL, 'kaimeite', NULL, NULL, '', 1001, '"+ DateUtil.dateToDefaultFull(new Date()) +"', 1001, '"+ DateUtil.dateToDefaultFull(new Date()) +"', 0, NULL, 0, 0, NULL, NULL, 0);");
            }

            // 全部读取完成被调用
            @Override
            public void doAfterAllAnalysed(AnalysisContext analysisContext) {
                //System.out.println("全部读取完成");
            }
        }).sheet().doRead();
    }
}
